package servlet;

import bean.RecordoutBean;
import util.JdbcUtil;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class OutboundreModifyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int outid =Integer.parseInt(request.getParameter("outid"));
        String sql ="SELECT * FROM record_out Where outid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,outid);
            ResultSet set = ps.executeQuery();
            set.absolute(1);
            RecordoutBean reo = new RecordoutBean();
            reo.setOutid(set.getInt(1));
            reo.setWid(set.getInt(2));
            reo.setType(set.getString(3));
            reo.setRname(set.getString(4));
            reo.setPrice(set.getDouble(5));
            reo.setNumber(set.getDouble(6));
            reo.setTime(set.getString(7));
            HttpSession session = request.getSession();
            session.setAttribute("reo",reo);
            request.getRequestDispatcher("outboundremodify.jsp").forward(request,response);

        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }
}

